package com.zy.ioc.pro4_ioc_factorybean;

import org.springframework.beans.factory.FactoryBean;

import java.util.Random;

/**
 * @program: mavenTest153
 * @description:
 * @author: zy
 * @create: 2025-07-12 17:10
 */
public class FruitFactoryBean  implements FactoryBean<Fruit> {

    public FruitFactoryBean() {
        System.out.println("FruitFactoryBean的构造方法");
    }


    @Override
    public Fruit getObject() throws Exception {
        //去类路径下去找 是否存在 某种Fruit接口的实现类
        Random r=new Random();
        int num=r.nextInt(3);
        if(num==0){
            return new Apple_A();
        }else if( num==1){
            return new Apple_B();
        }else{
            return null;
        }

    }

    @Override
    public Class<?> getObjectType() {
        return Fruit.class;
    }
}
